# -*- coding: utf-8 -*-
# @Time:2021/04/18 15:29
# @Author:Cindy
from time import sleep
from appium.webdriver.common.mobileby import MobileBy
from pages.base_page import BasePage


class AddMember(BasePage):

    def add_member(self, name, phone):
        from pages.contact_page import Contact
        self.driver.find_element(MobileBy.XPATH, "//*[@text='手动输入添加']").click()
        # 输入姓名
        self.driver.find_element(MobileBy.ID, "com.tencent.wework:id/ays").send_keys(name)
        # 输入手机号
        self.driver.find_element(MobileBy.ID, "com.tencent.wework:id/f4m").send_keys(phone)
        # 点击保存
        self.driver.find_element(MobileBy.XPATH, "//*[@text='保存']").click()
        # print(self.driver.page_source)
        # 获取toast
        # print(self.driver.find_element(MobileBy.XPATH, "//*[contains(@text, '添加成功')]").text)
        print(self.driver.find_element(MobileBy.XPATH, "//*[@class='android.widget.Toast']").text)
        # 返回上一级
        self.driver.find_element(MobileBy.ID, "com.tencent.wework:id/h86").click()
        sleep(3)
        return Contact(self.driver)
